package com.example.demo.web.im.service;

import java.io.IOException;
import org.dromara.hutool.core.text.StrUtil;
import org.noear.solon.annotation.Component;
import org.noear.solon.net.websocket.WebSocket;

/**
 * @author airhead
 */
@Component
public class ImService {
  public void onOpen(WebSocket socket) {
    String token = socket.param("token");
    if (StrUtil.isBlank(token)) {
      socket.close();
    }

    // 省略了管理 socket 的管理
  }

  public void onMessage(WebSocket socket, String text) throws IOException {
    // 省略了判断发送socket的逻辑

    socket.send("> " + text + "\r\n" + "消息已阅");
  }
}
